﻿Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Serialization
Imports System.Web.Script.Services
Imports TxCanViajes

' Para permitir que se llame a este servicio Web desde un script, usando ASP.NET AJAX, quite la marca de comentario de la siguiente línea.
' <System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<ScriptService()> _
Public Class Service
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function


    <WebMethod()> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function GetSemaforoAutobusList(ByVal ordenar As String, ByVal mes As String, ByVal anio As String) As String
        Dim jsonString = String.Empty
        Try

            If ordenar <> Nothing And mes <> Nothing Then
                Dim serializer As New JavaScriptSerializer
                Dim txCanViajes As New TxCanViajes
                If mes.Length > 0 AndAlso anio.Length > 0 Then
                    Dim dteInicial As DateTime = Nothing
                    Dim dteFinal As DateTime = Nothing
                    Dim lista As List(Of SemaforoAutobus) = Nothing
                    Dim strMetaMes As String = String.Empty
                    Dim strFactorAmarillo As String = String.Empty
                    dteInicial = New DateTime(Convert.ToInt32(anio), Convert.ToInt32(mes), 1)
                    dteInicial = Utilerias.convertirDateToDateHHMMSS(dteInicial, 0, 0, 1)
                    dteFinal = Utilerias.convertirDateToDateHHMMSS(Utilerias.UltimoDiaDelMesDesdeDateTime(dteInicial), 23, 59, 59)
                    strMetaMes = txCanViajes.GetMetaCombustible(1, 9, mes, anio)
                    strFactorAmarillo = txCanViajes.GetFactorAmarillo()
                    lista = txCanViajes.GetSemaforoAutobuses(ordenar, dteInicial, dteFinal, 1, 9, strMetaMes, strFactorAmarillo)

                    If Not lista Is Nothing AndAlso lista.Count > 0 Then
                        jsonString = serializer.Serialize(lista)
                    End If

                End If
            End If

        Catch ex As Exception

        End Try
        Return jsonString
    End Function

    <WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function GetSemaforoConductorList(ByVal ordenar As String, ByVal mes As String, ByVal anio As String) As String
        Dim jsonString = String.Empty
        Try

            If ordenar <> Nothing And mes <> Nothing Then
                Dim serializer As New JavaScriptSerializer
                Dim txCanViajes As New TxCanViajes
                If mes.Length > 0 AndAlso anio.Length > 0 Then
                    Dim dteInicial As DateTime = Nothing
                    Dim dteFinal As DateTime = Nothing
                    Dim lista As List(Of SemaforoConductor) = Nothing
                    Dim strMetaMes As String = String.Empty
                    Dim strFactorAmarillo As String = String.Empty
                    dteInicial = New DateTime(Convert.ToInt32(anio), Convert.ToInt32(mes), 1)
                    dteInicial = Utilerias.convertirDateToDateHHMMSS(dteInicial, 0, 0, 1)
                    dteFinal = Utilerias.convertirDateToDateHHMMSS(Utilerias.UltimoDiaDelMesDesdeDateTime(dteInicial), 23, 59, 59)
                    strMetaMes = txCanViajes.GetMetaCombustible(1, 9, mes, anio)
                    strFactorAmarillo = txCanViajes.GetFactorAmarillo(1, 9)
                    lista = txCanViajes.GetSemaforoConductores(ordenar, dteInicial, dteFinal, 1, 9, strMetaMes, strFactorAmarillo)

                    If Not lista Is Nothing AndAlso lista.Count > 0 Then
                        jsonString = serializer.Serialize(lista)
                    End If

                End If
            End If

        Catch ex As Exception

        End Try
        Return jsonString
    End Function




End Class